package com.yike.product.controller;

import com.yike.product.param.GoodsSpecificationParam;
import com.yike.product.service.GoodsSpecificationService;
import com.yike.product.vo.GoodsSpecificationVo;
import lombok.extern.slf4j.Slf4j;
import com.yike.product.param.GoodsSpecificationPageParam;
import com.yike.common.base.BaseController;
import com.yike.common.api.ApiResult;
import com.yike.common.pagination.Paging;
import com.yike.common.log.Module;
import com.yike.common.log.OperationLog;
import com.yike.common.enums.OperationLogType;
import com.yike.common.api.Add;
import com.yike.common.api.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品规格 控制器
 *
 * @author Sakura
 * @since 2024-10-18
 */
@Slf4j
@RestController
@RequestMapping("/platform/goodsSpecification")
@Module("product")
@Api(value = "商品规格API", tags = {"平台商品规格"})
public class GoodsSpecificationController extends BaseController {

    @Autowired
    private GoodsSpecificationService goodsSpecificationService;

    /**
     * 添加商品规格
     */
    @PostMapping("/add")
    @OperationLog(name = "添加商品规格", type = OperationLogType.ADD)
    @ApiOperation(value = "添加商品规格", response = ApiResult.class)
    public ApiResult<Boolean> addGoodsSpecification(@Validated(Add.class) @RequestBody GoodsSpecificationParam goodsSpecificationParam) throws Exception {
        boolean flag = goodsSpecificationService.saveGoodsSpecification(goodsSpecificationParam);
        return ApiResult.result(flag);
    }

    /**
     * 修改商品规格
     */
    @PostMapping("/update")
    @OperationLog(name = "修改商品规格", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改商品规格", response = ApiResult.class)
    public ApiResult<Boolean> updateGoodsSpecification(@Validated(Update.class) @RequestBody GoodsSpecificationParam goodsSpecificationParam) throws Exception {
        boolean flag = goodsSpecificationService.updateGoodsSpecification(goodsSpecificationParam);
        return ApiResult.result(flag);
    }

    /**
     * 删除商品规格
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除商品规格", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除商品规格", response = ApiResult.class)
    public ApiResult<Boolean> deleteGoodsSpecification(@PathVariable("id") Long id) throws Exception {
        boolean flag = goodsSpecificationService.deleteGoodsSpecification(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取商品规格详情
     */
    @GetMapping("/info/{id}")
    //@OperationLog(name = "商品规格详情", type = OperationLogType.INFO)
    @ApiOperation(value = "商品规格详情", response = GoodsSpecificationVo.class)
    public ApiResult<GoodsSpecificationVo> getGoodsSpecification(@PathVariable("id") Long id) throws Exception {
        GoodsSpecificationVo goodsSpecificationVo = goodsSpecificationService.getGoodsSpecification(id);
        return ApiResult.ok(goodsSpecificationVo);
    }

    /**
     * 商品规格分页列表
     */
    @PostMapping("/getPageList")
    //@OperationLog(name = "商品规格分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "商品规格分页列表", response = GoodsSpecificationVo.class)
    public ApiResult<Paging<GoodsSpecificationVo>> getGoodsSpecificationPageList(@Validated @RequestBody GoodsSpecificationPageParam goodsSpecificationPageParam) throws Exception {
        Paging<GoodsSpecificationVo> paging = goodsSpecificationService.getGoodsSpecificationPageList(goodsSpecificationPageParam);
        return ApiResult.ok(paging);
    }

}

